package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"gorm.io/gorm"
	"jd-mall/jd_srv/internal/svc"
	"jd-mall/jd_srv/jd_srv"
	"jd-mall/models/mysql"
)

type UploadLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
	return &UploadLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UploadLogic) Upload(in *jd_srv.UploadRequest) (*jd_srv.UploadResponse, error) {
	// todo: add your logic here and delete this line
	shopImage := mysql.ShopImage{
		Model:     gorm.Model{},
		ShopId:    int(in.ShopId),
		ShopImage: in.ImageUrl,
		IsMain:    "false",
	}
	imgId := shopImage.ImageUpload()
	return &jd_srv.UploadResponse{
		ImageId: int64(imgId),
	}, nil
}
